package com.ddx.task;

import com.ddx.common.util.AliyunVideoUtil;
import com.ddx.dao.ShortVideoMapper;
import com.ddx.pojo.ShortVideo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author dudianbo
 * @ClassName: ${CLASSNAME}
 * @Description: ${DESCRIPTION}
 * @date 2019/1/2
 */
//@Component
public class VideoUrlTask {
    private static Logger log = LoggerFactory.getLogger(VideoUrlTask.class);

    @Autowired
    ShortVideoMapper shortVideoMapper;

//    @Scheduled(fixedDelay = 60000)
    public void afterPropertiesSet() throws Exception {
        List<ShortVideo> list= shortVideoMapper.videoUrlNull(1000);
        if(list!=null){
           for(ShortVideo shortVideo:list) {
               try {
                   log.info("查询当前视频videoId={}", shortVideo.getVideoId());
                   ShortVideo update = new ShortVideo();
                   update.setVideoUrl(AliyunVideoUtil.getPlayInfo(shortVideo.getVideoId()).get("playURL"));
                   update.setCoverUrl(AliyunVideoUtil.getPlayInfo(shortVideo.getVideoId()).get("coverURL"));
                   update.setId(shortVideo.getId());
                   shortVideoMapper.updateByPrimaryKeySelective(update);
               }catch (Exception e){
                   log.error("上传视频有异常{}",e);
               }
           }
        }
    }
}
